package com.softeem.iov.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.GifCaptcha;
import cn.hutool.core.lang.Console;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 公共控制器:
 * 图片验证码
 * 发送短信
 * 发送邮件等
 */
@RequestMapping("/comm")
@RestController
public class CommController {

    @GetMapping("/captcha")
    public void captcha(HttpServletResponse response) throws IOException {
        //创建git验证码(验证码的宽度，高度，字符数)
        GifCaptcha cap = CaptchaUtil.createGifCaptcha(120, 40, 4);
        //获取验证码的文本内容
        String code = cap.getCode();
        //通过响应对象输入流将验证码响应到客户端
        cap.write(response.getOutputStream());
        Console.log("生成的验证码：" + code);
    }

}
